package com.xitang.customer.controller;

import com.xitang.common.bean.BizUser;
import com.xitang.common.dto.ResultVO;
import com.xitang.common.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

@Api(tags = "用户接口列表-客户")
@RestController
public class BizUserController extends BaseCustomerController {
    @Autowired
    private IUserService userService;

    @ApiOperation(value = "获取业务用户信息", notes = "根据微信ID获取业务用户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "vxId", value = "微信ID", dataType = "String")
    })
    @GetMapping("/biz_user/{vxId}")
    public ResultVO<BizUser> listBizUsers(@PathVariable(value = "vxId") String vxId) {
        BizUser bizUser = userService.getBizUser(vxId);
        if (Objects.isNull(bizUser)) {
            return ResultVO.error(null);
        }
        return ResultVO.success(bizUser);
    }

    @ApiOperation(value = "新增业务用户", notes = "新增业务用户")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = "bizUser", value = "用户信息", dataTypeClass = BizUser.class)
    })
    @PostMapping("/biz_user")
    public ResultVO<Integer> addBizUser(@RequestBody BizUser bizUser) {
        return ResultVO.success(userService.addBizUser(bizUser));
    }
}
